home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / modeler / plot.lwm < prev    next >
Text File  |  1993-12-13  |  3KB  |  140 lines

  1. /* CMD: Plot & Turn
  2.  *
  3.  * Plot a 1-D line function as a set of connected segments.
  4.  * Optionally create surface of revolution by specifying start, end angles
  5.  * by Stuart Ferguson (with trivial lathe addition by Arnie)
  6.  * Sat May  8 16:01:54 1993
  7.  */
  8.  
  9. call addlib "LWModelerARexx.port", 0
  10. signal on error
  11. signal on syntax
  12.  
  13. MATHLIB="rexxmathlib.library"
  14. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  15.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  16.     call notify(1,"!Can't find "MATHLIB)
  17.     exit
  18.     END
  19. call addlib "rexxsupport.library", 0, -30, 0
  20. sysnam = 'Plot Function'
  21. filnam = 'ENV:plot.state'
  22. version = 'Plot and Turn v1.0'
  23.  
  24. /* Setup state.  Read stored one, if any.
  25.  */
  26. ind = 2
  27. dep = 1
  28. lo  = 0
  29. hi  = 6.3
  30. n   = 20
  31. fun = "sin(x)*exp(-x/3) + 0.5 + x/"hi
  32. dfun= fun
  33. typ=2
  34. startangle=0
  35. angle=300
  36. sides=16
  37. if (exists(filnam)) then do
  38.     if (~open(state, filnam, 'R')) then break
  39.     if (readln(state) ~= version) then break
  40.     parse value readln(state) with ind dep lo hi n startangle angle sides typ .
  41.     fun = readln(state)
  42.     call close state
  43. end
  44.  
  45. call req_begin sysnam
  46.  
  47. id_ind = req_addcontrol("Independent Axis", 'c', 'X Y Z')
  48. id_dep = req_addcontrol("Dependent Axis", 'c', 'X Y Z')
  49. id_lo  = req_addcontrol("Low",  'n', 1)
  50. id_hi  = req_addcontrol("High", 'n', 1)
  51. id_ns  = req_addcontrol("Segments", 'n')
  52. id_fun = req_addcontrol("Function", 's', 35)
  53. StAngId = req_addcontrol("Start Angle",'N',0)
  54. AngId = req_addcontrol("End Angle",'N',0)
  55. id_sides  = req_addcontrol("Sides", 'n')
  56. id_typ = req_addcontrol("Build: ","CH","Points Polys Curves")
  57.  
  58. call req_setval id_ind, ind
  59. call req_setval id_dep, dep
  60. call req_setval id_lo,  lo
  61. call req_setval id_hi,  hi
  62. call req_setval id_ns,  n
  63. call req_setval id_fun, fun, dfun
  64. call req_setval StAngId, startangle,0
  65. call req_setval AngId, angle,0
  66. call req_setval id_sides,  sides
  67. call req_setval id_typ, typ,typ
  68.  
  69. if (~req_post()) then do
  70.     call req_end
  71.     exit
  72. end
  73. req=1
  74. ind = req_getval(id_ind)
  75. dep = req_getval(id_dep)
  76. n   = req_getval(id_ns) % 1
  77. lo  = req_getval(id_lo)
  78. hi  = req_getval(id_hi)
  79. typ  = req_getval(id_typ)
  80. fun = req_getval(id_fun)
  81. startangle = req_getval(StAngId)
  82. angle = req_getval(AngId)
  83. sides = req_getval(id_sides)
  84. call req_end
  85.  
  86. if (ind = dep) then do
  87.     call notify 1, '@'sysnam, "!Independent and dependent
  88.  axes must be different."
  89.     exit
  90. end
  91.  
  92. /* Save state now, in case something fails. */
  93. if (open(state, filnam, 'W')) then do
  94.     call writeln state, version
  95.     call writeln state, ind dep lo hi n startangle angle sides typ
  96.     call writeln state, fun
  97.     call close state
  98. end
  99.  
  100. do i = 1 to 3
  101.     if (ind = i) then cx.i = 1
  102.     else if (dep = i) then cx.i = 2
  103.     else cx.i = 3
  104. end i
  105. ifunc = "v =" fun
  106. call CUT()
  107. crv=""
  108. call add_begin
  109. call meter_begin n+2,'Plotting 'n' points.', ifunc
  110. do i = 0 to n
  111.     x = lo + (hi - lo) * i / n
  112.     y = x
  113.     z = x
  114.     interpret ifunc
  115.  
  116.     cvec = x v 0
  117.     vec = word(cvec, cx.1) word(cvec, cx.2) word(cvec, cx.3)
  118.  
  119.     crv = crv add_point(vec)
  120.     if (i ~= 0 & typ=2) then call add_polygon i i+1
  121.     call meter_step
  122. end i
  123. if typ=3 then call add_curve(crv)
  124. say ind translate(ind,"XYZ","123")
  125. call meter_end
  126. call add_end
  127.  
  128. if ( ( (startangle~=0) | (angle~=0) ) & (sides>0)) then do
  129.   sides=((sides*(angle-startangle)/360)%1)
  130.   call LATHE(translate(ind,"XYZ","123"),sides,0,angle,startangle)
  131.   end
  132. call PASTE()
  133. exit
  134.  
  135. syntax:
  136. error:
  137.   call end_all
  138.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  139.     exit
  140.